﻿/*
20101022
加入 label 參數, 可 overlayer 文字或圖片於 SmartButton 上.
以方便用作量產化 button.
 + String 或 Number 時使用 MyText 類, 並自動計算 text.size 且自動置中.


ref:
SmartButton
自動辦識 MovieClip 上的影格名稱 up,over,out,down, 並進行播放
*/
package com.cf.core.model{
	// import flash.events.MouseEvent;
	import com.cf.core.events.UIEvent;
	import com.cf.core.view.MyText;
	import com.cf.core.model.SmartButton;
	import com.cf.core.Utils.debug;
	public class SmartButtonEX extends SmartButton{
		
		private var G_label:*=new Object();
		public function get label():*{return G_label}
		public function set label(_o:*):void{
			if(alert) debug.msg("SmartButtonEX: Tag type is "+typeof(_o) );
			switch( typeof(_o) ){
				case "object": case "sprite": case "movieclip":
					G_label=_o;
				break;
				case "string": case "number": case "int":
					G_label=new MyText();
					G_label.text = _o;
					var s1:Number = Math.ceil(this.width / G_label.text.length);
					var s2:Number = Math.ceil(this.height * 0.6);
					if(alert) debug.msg("SmartButtonEX : width="+this.width+" height "+this.height+" ,label<"+_o+">, :: Auto size["+s1+"]or["+s2+"]");
					G_label.size = (s1<s2)? s1 : s2;
					CENTER();
				break;
			}//case
			this.addChildAt(G_label , 1);
		}//fn
		public function CENTER():void{
			G_label.x = this.width/2 - G_label.width/2;		// Label Center X
			G_label.y = this.height/2 - G_label.height/2;	// Label Center Y
		}//fn
		
		private var G_onClick:Function;
		public function set onClick(_f:Function):void{
			G_onClick=_f;
			this.addEventListener(UIEvent.CLICK, G_onClick);
		}//fn
		
		private var G_onDown:Function;
		public function set onDown(_f:Function):void{
			G_onDown=_f;
			this.addEventListener(UIEvent.DOWN, G_onDown);
		}//fn
		
		private var G_onUp:Function;
		public function set onUp(_f:Function):void{
			G_onUp=_f;
			this.addEventListener(UIEvent.UP, G_onUp);
		}//fn
		
		private var G_onOver:Function;
		public function set onOver(_f:Function):void{
			G_onOver=_f;
			this.addEventListener(UIEvent.OVER, G_onOver);
		}//fn
		
		private var G_onOut:Function;
		public function set onOut(_f:Function):void{
			G_onOut=_f;
			this.addEventListener(UIEvent.OUT, G_onOut);
		}//fn
	}//class
}//package